<template>
  <div id="vestTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="选择运营人员" prop="operateId">
          <el-select
            clearable
            v-model="formInline.operateId"
            filterable
            placeholder="所有"
          >
            <el-option
              v-for="(item, index) in operaPeopleList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="绑定状态" prop="unbound">
          <el-select v-model="formInline.unbound" clearable placeholder="所有">
            <el-option
              v-for="item in bindStatusList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开启状态" prop="robotStatus">
          <el-select
            v-model="formInline.robotStatus"
            clearable
            placeholder="所有"
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 输入搜索部分 -->
        <el-form-item label="马甲昵称/手机号/大鹏号" prop="content">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="请输入马甲昵称/手机号/大鹏号"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序规则" prop="sort">
          <el-select v-model="formInline.sort" placeholder="所有">
            <el-option
              v-for="item in sortList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="马甲等级" prop="robotGrade">
          <el-select v-model="formInline.robotGrade" clearable>
            <el-option
              v-for="item in robGradeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getDpNum } from '@/api/system/user'
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'TopSearch',
  msg: '评论库管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          operateId: '', // 运营人员,默认所有
          unbound: '', // 绑定,默认所有
          content: '', // 搜索框内容
          robotStatus: '', // 开启状态
          sort: '', // 排序规则
          robotGrade: '' // 马甲等级
        }
      }
    }
  },
  data() {
    return {
      // 运营人员列表
      operaPeopleList: [{ nickname: '所有', dapengUserId: '' }],
      // 绑定状态列表
      bindStatusList: [
        { key: '所有', value: '' },
        { key: '未绑定', value: '0' },
        { key: '已绑定', value: '1' }
      ],
      statusList: [{ dictLabel: '所有', dictValue: '' }],
      sortList: [],
      robGradeList: [{ dictLabel: '全部', dictValue: '' }],
      rules: {
        operateId: [{ required: false, trigger: 'blur' }],
        unbound: {},
        content: {},
        robotStatus: {},
        sort: {},
        robotGrade: {}
      }
    }
  },
  mounted() {
    this.getStickList()
    this.getStatusList()
  },
  methods: {
    /* 获取选择运营人员 */
    getStickList() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.operaPeopleList = this.operaPeopleList.concat(response)
      })
    },
    async getStatusList() {
      // 马甲开启关闭状态
      let data = await sysNormalDisable('robot_status', 'robotStatus')
      this.statusList = this.statusList.concat(data)
      // 马甲等级
      let robGrade = await sysNormalDisable('robot_grade', 'robGrade')
      this.robGradeList = this.robGradeList.concat(robGrade)
      // 马甲排序规则
      this.sortList = await sysNormalDisable('robot_order_rule')
      this.setDefaultValue()
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.sort = this.sortList[0].dictValue
    },
    // 搜索
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  }
}
</script>
<style lang="less">
#vestTopSearch {
  .numberInput {
    width: 200px;
  }
  .el-input {
    &.el-input--suffix {
      width: 160px !important;
    }
  }
}
</style>
